package com.ss.android.article.base.feature.detail.presenter;

import android.content.Context;
import android.graphics.ColorFilter;
import android.net.Uri;
import android.support.v4.content.ContextCompat;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bytedance.article.common.c.TTUtils;
import com.bytedance.common.utility.Logger;
import com.bytedance.common.utility.UIUtils;
import com.bytedance.frameworks.baselib.network.http.util.TaskInfo;
import com.ss.android.action.b.FeedViewHolder;
import com.ss.android.article.base.app.AppData;
import com.ss.android.article.base.feature.app.a.ArticleConstants;
import com.ss.android.article.base.feature.detail.model.ForumPostData;
import com.ss.android.article.base.feature.detail.model.CommentWrapper;
import com.ss.android.article.base.utils.JSONObjectWrapper;
import com.ss.android.article.browser.R;
import com.ss.android.article.common.ThumbGridLayout;
import com.ss.android.common.lib.MobClickCombiner;
import com.ss.android.common.callback.SSCallback;
import com.ss.android.image.BaseImageManager;
import com.ss.android.image.loader.ImageLoader;
import com.ss.android.image.model.ImageInfo;
import com.ss.android.model.AbsArticle;

import org.json.JSONObject;

import java.util.List;

public final class f extends FeedViewHolder implements View.OnClickListener {
    public CommentWrapper A;
    public Context o;
    public View p;
    public ImageView q;
    public TextView r;
    public TextView s;
    public TextView t;
    public TextView u;
    public ThumbGridLayout v;
    public TextView w;
    public ViewGroup x;
    public View y;
    public SSCallback z;
    private AppData B;
    private ImageLoader C;
    private ColorFilter D;
    private boolean E;

    public f(Context context, ImageLoader imageLoader) {
        this.o = context;
        this.B = AppData.getInstance();
        this.D = TTUtils.getNightModeColorFilter();
        new TaskInfo();
        new BaseImageManager(context);
        this.C = imageLoader;
    }

    public final void a(AbsArticle arg11, CommentWrapper arg12, boolean arg13) {
        JSONObject v8;
        long v4_1;
        long v6;
        String v2;
        String v0_1 = null;
        if (arg12 == null) {
            return;
        }

        if (arg12.mForumPostData == null) {
            return;
        }

        if (arg11 == null) {
            return;
        }

        this.A = arg12;
        this.d();
        ForumPostData v9 = arg12.mForumPostData;
        if (v9.forumLink != null) {
            v0_1 = v9.forumLink.b;
        }

        if (!android.support.design.a.isTextEmpty(v9.url) && (arg13)) {
            Uri v1 = Uri.parse(v9.url);
            try {
                String v4 = v1.getQueryParameter("fid");
                v2 = v1.getQueryParameter("tid");
                String v1_2 = v1.getQueryParameter("cid");
                long v2_1 = android.support.design.a.isTextEmpty(v2) ? 0 : Long.valueOf(v2).longValue();
                v6 = android.support.design.a.isTextEmpty(v4) ? 0 : Long.valueOf(v4).longValue();
                v4_1 = android.support.design.a.isTextEmpty(v1_2) ? 0 : Long.valueOf(v1_2).longValue();
                v8 = new JSONObjectWrapper().put("thread_id", v2_1).jsonObject;
                boolean v1_3 = AppData.getInstance().D();
                v2 = v1_3 ? "concern_page" : "forum_detail";
                if (!v1_3) {
                    v4_1 = v6;
                }
                MobClickCombiner.onEvent(this.o, v2, "show_detail_comment_ad", v4_1, arg11.groupId, v8);
            } catch (Exception v1_1) {
                label_131:
                if (Logger.debug()) {
                    v1_1.printStackTrace();
                }
            }
        }
        UIUtils.setTextAndVisibility(this.t, ((CharSequence) v0_1));
        UIUtils.setTextAndVisibility(this.s, v9.content);
        this.s.setOnLongClickListener(new com.ss.android.article.base.feature.detail.presenter.g(this));
        if (!android.support.design.a.isTextEmpty(v9.userName)) {
            this.u.setVisibility(View.VISIBLE);
            this.u.setText(String.format(this.o.getResources().getString(com.ss.android.article.browser.R.string.comment_forum_author_format), v9.userName));
        } else {
            this.u.setVisibility(View.GONE);
        }

        int v0_2 = this.B.mFontSizePref;
        if (v0_2 < 0 || v0_2 > 3) {
            v0_2 = 0;
        }

        this.s.setTextSize(((float) ArticleConstants.J[v0_2]));
        this.t.setTextSize(((float) ArticleConstants.J[v0_2]));
        if (v9.imageList == null || v9.imageList.size() <= 0) {
            this.x.setVisibility(View.GONE);
        } else {
            this.x.setVisibility(View.VISIBLE);
            List<ImageInfo> v3 = v9.imageList;
            v0_2 = this.v.getChildCount();
            int v4_2 = Math.min(3, v3.size());
            if (v4_2 > v0_2) {
                while (v0_2 < v4_2) {
                    ImageView v1_4 = new ImageView(this.o);
                    v1_4.setScaleType(ImageView.ScaleType.FIT_CENTER);
                    this.v.addView(((View) v1_4));
                    ++v0_2;
                }
            } else if (v4_2 < v0_2) {
                --v0_2;
                while (v0_2 >= v4_2) {
                    this.v.removeViewAt(v0_2);
                    --v0_2;
                }
            }

            int v2_2;
            for (v2_2 = 0; v2_2 < v4_2; ++v2_2) {
                ImageView v0_3 = (ImageView) this.v.getChildAt(v2_2);
                ColorFilter v1_5 = this.E ? this.D : null;
                v0_3.setColorFilter(v1_5);
                v0_3.setScaleType(ImageView.ScaleType.CENTER_CROP);
                v0_3.setBackgroundResource(com.ss.android.article.browser.R.drawable.simple_image_holder_listpage);
                this.C.loadImage(v0_3, v3.get(v2_2), false);
            }

            if (v4_2 == 1) {
                this.v.setSingleSize(v3.get(0).mWidth, v3.get(0).mHeight);
            }

            if (v3.size() > 3) {
                this.w.setVisibility(View.VISIBLE);
            } else {
                this.w.setVisibility(View.GONE);
            }
        }

        switch (arg12.e) {
            case 0: {
                label_186:
                this.y.setVisibility(View.VISIBLE);
                return;
            }
            case 2: {
                label_198:
                this.y.setVisibility(View.INVISIBLE);
                return;
            }
        }

        return;


    }

    public final void d() {
        int v3 = R.color.ssxinzi2;
        boolean v0 = AppData.isNightMode();
        if (v0 != this.E) {
            this.E = v0;
            this.p.setBackgroundResource(com.ss.android.article.browser.R.drawable.comment_forum_item_bg);
            this.q.setImageResource(com.ss.android.article.browser.R.drawable.up);
            this.r.setTextColor(ContextCompat.getColorStateList(this.o, v3));
            this.t.setBackgroundResource(com.ss.android.article.browser.R.drawable.comment_forum_title_bg);
            this.t.setTextColor(ContextCompat.getColorStateList(this.o, R.color.update_comment_more_text_selector));
            this.s.setTextColor(ContextCompat.getColorStateList(this.o, v3));
            this.u.setTextColor(ContextCompat.getColorStateList(this.o, R.color.ssxinzi3));
            this.y.setBackgroundColor(ContextCompat.getColor(this.o, R.color.ssxinxian1));
            this.w.setTextColor(ContextCompat.getColorStateList(this.o, R.color.ssxinzi8));
            this.w.setBackgroundResource(com.ss.android.article.browser.R.drawable.detail_ad_taobao_image_lable);
        }
    }

    public final void onClick(View arg7) {
        Object[] v1;
        SSCallback v0;
        int v2 = 3;
        int v4 = 2;
        if (this.z != null) {
            if (arg7 == this.p) {
                v0 = this.z;
                v1 = new Object[v2];
                v1[0] = Integer.valueOf(1);
                v1[1] = this;
                v1[v4] = arg7;
                v0.onCallback(v1);
            } else if (arg7 == this.s) {
                v0 = this.z;
                v1 = new Object[v2];
                v1[0] = Integer.valueOf(v4);
                v1[1] = this;
                v1[v4] = arg7;
                v0.onCallback(v1);
            } else if (arg7 == this.t) {
                v0 = this.z;
                v1 = new Object[v2];
                v1[0] = Integer.valueOf(v2);
                v1[1] = this;
                v1[v4] = arg7;
                v0.onCallback(v1);
            }
        }
    }
}

